package cn.tedu.note.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.tedu.note.dao.NoteDao;
import cn.tedu.note.service.NoteService;
import cn.tedu.note.service.NotebookNotFoundException;

@Service("noteService")
public class NoteServiceImpl implements NoteService {

	@Resource
	private NoteDao noteDao;
	
	

	public List<Map<String, Object>> listNotes(String notebookId)
			throws NotebookNotFoundException {
		
		if(notebookId==null||notebookId.trim().isEmpty()){
			throw new NotebookNotFoundException("笔记本Id不存在");
		}
		
		/**
		 * :在数据库中 通过查询notebookId对应的笔记本数确定notebook是否存在
		 * int n=notDao.countNotebookById(notebookId);
		 * if(n!=1){
		 * 		throw new NotebookNotFoundException("笔记本不存在");
		 *   }
		 * 
		 */
		List<Map<String,Object>> notebook = 
				noteDao.findNotebookByNotebookId(notebookId);
		if(notebook==null){
			throw new NotebookNotFoundException("笔记本不存在");
			
		}
		
		return noteDao.findNotesByNotebookId(notebookId);
		
	}

}

















